From 78819be401e70137467517f4811eb4de5541ecde Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Wed, 1 Aug 2018 19:21:18 -0600 Subject: [PATCH] eliminate queues in inifile. (#239) * eliminate queues in inifile replacing them with QHashs * replace use of gbfile in inifile with QTextStream --- bcr.cc | 51 +++++----- filter_vecs.cc | 15 +-- garmin_fs.cc | 5 +- garmin_txt.cc | 10 +- ggv_ovl.cc | 28 +++--- inifile.cc | 250 ++++++++++++++++++------------------------------- inifile.h | 22 +++-- raymarine.cc | 44 +++++---- vecs.cc | 35 ++++--- 9 files changed, 194 insertions(+), 266 deletions(-) diff --git a/bcr.cc b/bcr.cc index 5673327c5..7840a480d 100644 --- a/bcr.cc +++ b/bcr.cc @@ -27,10 +27,10 @@ */ #include "defs.h" -#include "cet_util.h" #include "csv_util.h" #include "garmin_tables.h" #include "inifile.h" +#include #include #include #include @@ -187,9 +187,6 @@ static void bcr_rd_init(const QString& fname) { ini = inifile_init(fname, MYNAME); - if (ini->unicode) { - cet_convert_init(CET_CHARSET_UTF8, 1); - } bcr_init_radius(); } @@ -245,11 +242,12 @@ bcr_mercator_to_wgs84(const int north, const int east, double* lat, double* lon) static void bcr_data_read() { - char* str; + QString str; route_head* route = route_head_alloc(); - if ((str = inifile_readstr(ini, "client", "routename"))) { + str = inifile_readstr(ini, "client", "routename"); + if (!str.isNull()) { route->rte_name = str; } @@ -258,15 +256,16 @@ bcr_data_read() for (int index = 1; index > 0; index ++) { char station[32]; - char* str; + QString str; int mlat, mlon; /* mercator data */ snprintf(station, sizeof(station), "STATION%d", index); - if (nullptr == (str = inifile_readstr(ini, "coordinates", station))) { + str = inifile_readstr(ini, "coordinates", station); + if (str.isNull()) { break; } - if (2 != sscanf(str, "%d,%d", &mlon, &mlat)) { + if (2 != sscanf(CSTR(str), "%d,%d", &mlon, &mlat)) { fatal(MYNAME ": structure error at %s (Coordinates)!\n", station); } @@ -275,32 +274,24 @@ bcr_data_read() wpt->shortname = station; bcr_mercator_to_wgs84(mlat, mlon, &wpt->latitude, &wpt->longitude); - if (nullptr != (str = inifile_readstr(ini, "client", station))) { - char* cx = strchr(str, ','); - if (cx == nullptr) { + str = inifile_readstr(ini, "client", station); + if (!str.isNull()) { + int cx = str.indexOf(','); + if (cx < 0) { fatal(MYNAME ": structure error at %s (Client)!\n", station); } - *cx++ = '\0'; - bcr_handle_icon_str(str, wpt); + bcr_handle_icon_str(CSTR(str.left(cx)), wpt); } - if (nullptr != (str = inifile_readstr(ini, "description", station))) { - char* c = strchr(str, ','); - if (c != nullptr) { - *c = '\0'; - } - if (*str) { - wpt->notes = str; + str = inifile_readstr(ini, "description", station); + if (!str.isNull()) { + QString note = str.section(',', 0, 0); + if (!note.isEmpty()) { + wpt->notes = note; } - if ((str = c)) { - str++; - c = strchr(str, ','); - if (c != nullptr) { - *c = '\0'; - } - if (*str) { - wpt->shortname = str; - } + QString shortname = str.section(',', 1, 1); + if (!shortname.isEmpty()) { + wpt->shortname = shortname; } } diff --git a/filter_vecs.cc b/filter_vecs.cc index 1bf3342b3..23e0443f5 100644 --- a/filter_vecs.cc +++ b/filter_vecs.cc @@ -42,7 +42,7 @@ #include "validate.h" #include "gbversion.h" #include "inifile.h" -#include +#include #include #include #include // qsort @@ -201,14 +201,15 @@ find_filter_vec(const char* const vecname, const char** opts) struct arglist* args = vec->vec->get_args(); if (args) { for (ap = args; ap->argstring; ap++) { - const char* temp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring); - if (temp == nullptr) { - temp = inifile_readstr(global_opts.inifile, "Common filter settings", ap->argstring); + QString qtemp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring); + if (qtemp.isNull()) { + qtemp = inifile_readstr(global_opts.inifile, "Common filter settings", ap->argstring); } - if (temp == nullptr) { - temp = ap->defaultvalue; + if (qtemp.isNull()) { + assign_option(vec->name, ap, ap->defaultvalue); + } else { + assign_option(vec->name, ap, CSTR(qtemp)); } - assign_option(vec->name, ap, temp); } } diff --git a/garmin_fs.cc b/garmin_fs.cc index fd7cae63b..1986a75e1 100644 --- a/garmin_fs.cc +++ b/garmin_fs.cc @@ -26,6 +26,7 @@ #include "garmin_tables.h" #include "inifile.h" +#include #include #include #include @@ -387,8 +388,8 @@ garmin_fs_convert_category(const char* category_name, uint16_t* category) // warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=] assert((i>=0) && (i<16)); snprintf(key, sizeof(key), "%d", i + 1); - char* c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key); - if ((c != nullptr) && (case_ignore_strcmp(c, category_name) == 0)) { + QString c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key); + if (c.compare(category_name, Qt::CaseInsensitive) == 0) { cat = (1 << i); break; } diff --git a/garmin_txt.cc b/garmin_txt.cc index 0191288d4..2c7fdb641 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -32,6 +32,7 @@ #include "jeeps/gpsmath.h" #include "strptime.h" +#include #include #include // qsort @@ -388,8 +389,6 @@ print_date_and_time(const time_t time, const int time_only) static void print_categories(uint16_t categories) { - char* c; - if (categories == 0) { return; } @@ -397,21 +396,20 @@ print_categories(uint16_t categories) int count = 0; for (int i = 0; i < 16; i++) { if ((categories & 1) != 0) { + QString c; if (global_opts.inifile != nullptr) { char key[3]; snprintf(key, sizeof(key), "%d", i + 1); c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key); - } else { - c = nullptr; } gbfprintf(fout, "%s", (count++ > 0) ? "," : ""); - if (c == nullptr) { + if (c.isNull()) { gbfprintf(fout, "Category %d", i+1); } // gbfprintf(fout, "%s", gps_categories[i]); else { - gbfprintf(fout, "%s", c); + gbfprintf(fout, "%s", CSTR(c)); } } diff --git a/ggv_ovl.cc b/ggv_ovl.cc index 263addefb..a837598d0 100644 --- a/ggv_ovl.cc +++ b/ggv_ovl.cc @@ -21,10 +21,10 @@ */ #include "defs.h" -#include "cet_util.h" #include "grtcirc.h" #include "inifile.h" +#include #include #include #include @@ -83,9 +83,6 @@ static void ggv_ovl_rd_init(const QString& fname) { inifile = inifile_init(fname, MYNAME); - if (inifile->unicode) { - cet_convert_init(CET_CHARSET_UTF8, 1); - } route_ct = 0; track_ct = 0; @@ -110,11 +107,12 @@ ggv_ovl_read() OVL_SYMBOL_TYP type = (OVL_SYMBOL_TYP) inifile_readint_def(inifile, symbol, "Typ", 0); int points = inifile_readint_def(inifile, symbol, "Punkte", -1); + QString lat; + QString lon; switch (type) { char coord[32]; Waypoint* wpt; - char* cx; int group; case OVL_SYMBOL_LINE: @@ -143,15 +141,17 @@ ggv_ovl_read() wpt = new Waypoint; snprintf(coord, sizeof(coord), "YKoord%d", j); - if ((cx = inifile_readstr(inifile, symbol, coord))) { - wpt->latitude = atof(cx); + lat = inifile_readstr(inifile, symbol, coord); + if (!lat.isNull()) { + wpt->latitude = lat.toDouble(); } else { continue; } snprintf(coord, sizeof(coord), "XKoord%d", j); - if ((cx = inifile_readstr(inifile, symbol, coord))) { - wpt->longitude = atof(cx); + lon = inifile_readstr(inifile, symbol, coord); + if (!lon.isNull()) { + wpt->longitude = lon.toDouble(); } else { continue; } @@ -171,13 +171,15 @@ ggv_ovl_read() wpt = new Waypoint; wpt->shortname = symbol; - if ((cx = inifile_readstr(inifile, symbol, "YKoord"))) { - wpt->latitude = atof(cx); + lat = inifile_readstr(inifile, symbol, "YKoord"); + if (!lat.isNull()) { + wpt->latitude = lat.toDouble(); } else { continue; } - if ((cx = inifile_readstr(inifile, symbol, "XKoord"))) { - wpt->longitude = atof(cx); + lon = inifile_readstr(inifile, symbol, "XKoord"); + if (!lon.isNull()) { + wpt->longitude = lon.toDouble(); } else { continue; } diff --git a/inifile.cc b/inifile.cc index 8885d8d16..65b3300d9 100644 --- a/inifile.cc +++ b/inifile.cc @@ -18,38 +18,37 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ -#include "defs.h" +#include "defs.h" // for fatal, ugetenv, warning #include "inifile.h" -#include -#include -#include -#include +#include "src/core/file.h" // for File +#include // for QByteArray +#include // for operator==, QChar +#include // for QDir +#include // for QFile +#include // for QFileInfo +#include // for QHash +#include // for QIODevice::ReadOnly, QIODevice +#include // for QTextStream +#include // for CaseInsensitive +#include // for qPrintable #define MYNAME "inifile" -typedef struct inifile_entry_s { - queue Q; - char* key; - char* val; -} inifile_entry_t; +class InifileSection +{ +public: + QString name; + QHash entries; -typedef struct inifile_section_s { - queue Q; - char* name; - int ientries; - queue entries; -} inifile_section_t; + InifileSection() = default; + explicit InifileSection(QString nm) : name{nm} {} +}; /* internal procedures */ -#define START_BUFSIZE 257 -#define DELTA_BUFSIZE 128 - #define GPSBABEL_INIFILE "gpsbabel.ini" #define GPSBABEL_SUBDIR ".gpsbabel" -/* Remember the filename we used so we can include it in errors. */ -static QString gbinipathname; static QString find_gpsbabel_inifile(const QString& path) /* can be empty or NULL */ @@ -61,18 +60,18 @@ find_gpsbabel_inifile(const QString& path) /* can be empty or NULL */ return QFile(inipath).open(QIODevice::ReadOnly) ? inipath : QString(); } -static gbfile* +static QString open_gpsbabel_inifile() { - gbfile* res = nullptr; + QString res; QString envstr = ugetenv("GPSBABELINI"); if (!envstr.isNull()) { if (QFile(envstr).open(QIODevice::ReadOnly)) { - return gbfopen(envstr, "r", "GPSBabel"); + return envstr; } warning("WARNING: GPSBabel-inifile, defined in environment, NOT found!\n"); - return nullptr; + return res; } QString name = find_gpsbabel_inifile(""); // Check in current directory first. if (name.isNull()) { @@ -80,117 +79,83 @@ open_gpsbabel_inifile() // Use &&'s early-out behaviour to try successive file locations: first // %APPDATA%, then %WINDIR%, then %SYSTEMROOT%. (name = find_gpsbabel_inifile(ugetenv("APPDATA"))).isNull() - && (name = find_gpsbabel_inifile(ugetenv("WINDIR"))).isNull() - && (name = find_gpsbabel_inifile(ugetenv("SYSTEMROOT"))).isNull(); + && (name = find_gpsbabel_inifile(ugetenv("WINDIR"))).isNull() + && (name = find_gpsbabel_inifile(ugetenv("SYSTEMROOT"))).isNull(); #else // Use &&'s early-out behaviour to try successive file locations: first // ~/.gpsbabel, then /usr/local/etc, then /etc. (name = find_gpsbabel_inifile(QDir::home().filePath(GPSBABEL_SUBDIR))). - isNull() - && (name = find_gpsbabel_inifile("/usr/local/etc")).isNull() - && (name = find_gpsbabel_inifile("/etc")).isNull(); + isNull() + && (name = find_gpsbabel_inifile("/usr/local/etc")).isNull() + && (name = find_gpsbabel_inifile("/etc")).isNull(); #endif } if (!name.isNull()) { - res = gbfopen(name, "r", "GPSBabel"); - gbinipathname = name; + res = name; } return res; } static void -inifile_load_file(gbfile* fin, inifile_t* inifile, const char* myname) +inifile_load_file(QTextStream* stream, inifile_t* inifile, const char* myname) { - char* buf; - inifile_section_t* sec = nullptr; - int line = 0; + QString buf; + InifileSection section; - while ((buf = gbfgetstr(fin))) { - char* cin = lrtrim(buf); - - if ((line++ == 0) && fin->unicode) { - inifile->unicode = 1; - } + while (!(buf = stream->readLine()).isNull()) { + buf = buf.trimmed(); - if (*cin == '\0') { + if (buf.isEmpty()) { continue; /* skip empty lines */ } - if ((*cin == '#') || (*cin == ';')) { + if ((buf.at(0) == '#') || (buf.at(0) == ';')) { continue; /* skip comments */ } - if (*cin == '[') { - - char* cend = strchr(++cin, ']'); - - if (cend != nullptr) { - *cend = '\0'; - cin = lrtrim(cin); + if (buf.at(0) == '[') { + QString section_name; + if (buf.contains(']')) { + section_name = buf.mid(1, buf.indexOf(']') - 1).trimmed(); } - if ((*cin == '\0') || (cend == nullptr)) { - fatal("%s: invalid section header '%s' in '%s'.\n", myname, cin, - qPrintable(gbinipathname)); + if (section_name.isEmpty()) { + fatal("%s: invalid section header '%s' in '%s'.\n", myname, qPrintable(section_name), + qPrintable(inifile->source)); } - sec = (inifile_section_t*) xcalloc(1, sizeof(*sec)); - - sec->name = xstrdup(cin); - QUEUE_INIT(&sec->entries); - ENQUEUE_TAIL(&inifile->secs, &sec->Q); - inifile->isecs++; + // form lowercase key to implement CaseInsensitive matching. + section_name = section_name.toLower(); + inifile->sections.insert(section_name, InifileSection(section_name)); + section = inifile->sections.value(section_name); } else { - if (sec == nullptr) { + if (section.name.isEmpty()) { fatal("%s: missing section header in '%s'.\n", myname, - qPrintable(gbinipathname)); + qPrintable(inifile->source)); } - inifile_entry_t* entry = (inifile_entry_t*) xcalloc(1, sizeof(*entry)); - ENQUEUE_TAIL(&sec->entries, &entry->Q); - sec->ientries++; - - char* cx = strchr(cin, '='); - if (cx != nullptr) { - *cx = '\0'; - cin = lrtrim(cin); - } - - entry->key = xstrdup(cin); - - if (cx != nullptr) { - cx = lrtrim(++cx); - entry->val = xstrdup(cx); - } else { - entry->val = xstrdup(""); - } + // Store key in lower case to implement CaseInsensitive matching. + QString key = buf.section('=', 0, 0).trimmed().toLower(); + // Take some care so the return from inifile_find_value can + // be used to distinguish between a key that isn't found + // and a found key without a value, i.e. force value + // to be non-null but possibly empty. + QString value = buf.section('=', 1).append("").trimmed(); + section.entries.insert(key, value); + + // update the QHash sections with the modified InifileSection section. + inifile->sections.insert(section.name, section); } } } -static char* -inifile_find_value(const inifile_t* inifile, const char* sec_name, const char* key) +static const QString +inifile_find_value(const inifile_t* inifile, const QString& sec_name, const QString& key) { - queue* elem, *tmp; - if (inifile == nullptr) { - return nullptr; + return QString(); } - QUEUE_FOR_EACH(&inifile->secs, elem, tmp) { - inifile_section_t* sec = reinterpret_cast(elem); - - if (case_ignore_strcmp(sec->name, sec_name) == 0) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&sec->entries, elem, tmp) { - inifile_entry_t* entry = reinterpret_cast(elem); - - if (case_ignore_strcmp(entry->key, key) == 0) { - return entry->val; - } - } - } - } - return nullptr; + // CaseInsensitive matching implemented by forcing sec_name & key to lower case. + return inifile->sections.value(sec_name.toLower()).entries.value(key.toLower()); } /* public procedures */ @@ -205,86 +170,51 @@ inifile_find_value(const inifile_t* inifile, const char* sec_name, const char* k inifile_t* inifile_init(const QString& filename, const char* myname) { - gbfile* fin = nullptr; + QString name; if (filename.isEmpty()) { - fin = open_gpsbabel_inifile(); - if (fin == nullptr) { + name = open_gpsbabel_inifile(); + if (name.isEmpty()) { return nullptr; } } else { - fin = gbfopen(filename, "rb", myname); + name = filename; } - inifile_t* result = (inifile_t*) xcalloc(1, sizeof(*result)); - QUEUE_INIT(&result->secs); - inifile_load_file(fin, result, myname); + gpsbabel::File file(name); + file.open(QFile::ReadOnly); + QTextStream stream(&file); + stream.setCodec("UTF-8"); + stream.setAutoDetectUnicode(true); + + auto* result = new inifile_t; + QFileInfo fileinfo(file); + result->source = fileinfo.absoluteFilePath(); + inifile_load_file(&stream, result, myname); - gbfclose(fin); + file.close(); return result; } void inifile_done(inifile_t* inifile) { - if (inifile == nullptr) { - return; - } - - if (inifile->isecs > 0) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&inifile->secs, elem, tmp) { - inifile_section_t* sec = reinterpret_cast(elem); - - if (sec->ientries > 0) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&sec->entries, elem, tmp) { - inifile_entry_t* entry = reinterpret_cast(elem); - - if (entry->key) { - xfree(entry->key); - } - if (entry->val) { - xfree(entry->val); - } - dequeue(elem); - xfree(entry); - } - } - dequeue(elem); - if (sec->name) { - xfree(sec->name); - } - xfree(sec); - } - xfree(inifile); - } - gbinipathname.clear(); + delete inifile; } -int +bool inifile_has_section(const inifile_t* inifile, const char* section) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&inifile->secs, elem, tmp) { - inifile_section_t* sec = reinterpret_cast(elem); - if (case_ignore_strcmp(sec->name, section) == 0) { - return 1; - } - } - return 0; + return inifile->sections.contains(QString(section).toLower()); } /* inifile_readstr: - returns NULL if not found, otherwise a pointer to the value of key ... - all key values are valid entities until "inifile_done" + returns a null QString if not found, otherwise a non-null but possibly + empty Qstring with the value of key ... */ -char* +QString inifile_readstr(const inifile_t* inifile, const char* section, const char* key) { return inifile_find_value(inifile, section, key); @@ -299,14 +229,14 @@ inifile_readstr(const inifile_t* inifile, const char* section, const char* key) int inifile_readint(const inifile_t* inifile, const char* section, const char* key, int* value) { - char* str = inifile_find_value(inifile, section, key); + const QString str = inifile_find_value(inifile, section, key); - if (str == nullptr) { + if (str.isNull()) { return 0; } if (value != nullptr) { - *value = atoi(str); + *value = str.toInt(); } return 1; } diff --git a/inifile.h b/inifile.h index 8fc2bda3d..911633192 100644 --- a/inifile.h +++ b/inifile.h @@ -21,13 +21,15 @@ #ifndef HAVE_INIFILE_H #define HAVE_INIFILE_H -#include "defs.h" +#include // for QHash +#include // for QList +#include // for QString -typedef struct inifile_s { - int isecs; /* number of sections */ - queue secs; /* sections */ - uint8_t unicode:1; -} inifile_t; +class InifileSection; +struct inifile_t { + QHash sections; + QString source; +}; /* inifile_init: @@ -37,14 +39,14 @@ typedef struct inifile_s { inifile_t* inifile_init(const QString& filename, const char* myname); void inifile_done(inifile_t* inifile); -int inifile_has_section(const inifile_t* inifile, const char* section); +bool inifile_has_section(const inifile_t* inifile, const char* section); /* inifile_readstr: - returns NULL if not found, otherwise a pointer to the value of key ... - all key values are valid entities until "inifile_done" + returns a null QString if not found, otherwise a non-null but possibly + empty Qstring with the value of key ... */ -char* inifile_readstr(const inifile_t* inifile, const char* section, const char* key); +QString inifile_readstr(const inifile_t* inifile, const char* section, const char* key); /* inifile_readint: diff --git a/raymarine.cc b/raymarine.cc index ae6e1872e..2093519ca 100644 --- a/raymarine.cc +++ b/raymarine.cc @@ -44,10 +44,10 @@ */ #include "defs.h" -#include "cet_util.h" #include "csv_util.h" #include "inifile.h" +#include #include #include #include @@ -167,9 +167,6 @@ static void raymarine_rd_init(const QString& fname) { fin = inifile_init(fname, MYNAME); - if (fin->unicode) { - cet_convert_init(CET_CHARSET_UTF8, 1); - } } static void @@ -185,37 +182,43 @@ raymarine_read() for (unsigned int ix = 0; ix < 0x3FFF; ix++) { char sect[10]; - char* str, *name, *lat, *lon; + QString str, name, lat, lon; /* built section identifier */ snprintf(sect, sizeof(sect), "Wp%d", ix); /* try to read our most expected values */ - if (nullptr == (name = inifile_readstr(fin, sect, "Name"))) { + name = inifile_readstr(fin, sect, "Name"); + if (name.isNull()) { break; } - if (nullptr == (lat = inifile_readstr(fin, sect, "Lat"))) { + lat = inifile_readstr(fin, sect, "Lat"); + if (lat.isNull()) { break; } - if (nullptr == (lon = inifile_readstr(fin, sect, "Long"))) { + lon = inifile_readstr(fin, sect, "Long"); + if (lon.isNull()) { break; } Waypoint* wpt = new Waypoint; wpt->shortname = name; - wpt->latitude = atof(lat); - wpt->longitude = atof(lon); + wpt->latitude = lat.toDouble(); + wpt->longitude = lon.toDouble(); waypt_add(wpt); /* try to read optional values */ - if (((str = inifile_readstr(fin, sect, "Notes"))) && *str) { + str = inifile_readstr(fin, sect, "Notes"); + if (!str.isEmpty()) { wpt->notes = str; } - if (((str = inifile_readstr(fin, sect, "Time"))) && *str) { - wpt->SetCreationTime(EXCEL_TO_TIMET(atof(str))); + str = inifile_readstr(fin, sect, "Time"); + if (!str.isEmpty()) { + wpt->SetCreationTime(EXCEL_TO_TIMET(str.toDouble())); } - if (((str = inifile_readstr(fin, sect, "Bmp"))) && *str) { - unsigned int symbol = atoi(str); + str = inifile_readstr(fin, sect, "Bmp"); + if (!str.isEmpty()) { + unsigned int symbol = str.toInt(); if ((symbol < 3) && (symbol >= RAYMARINE_SYMBOL_CT)) { symbol = RAYMARINE_STD_SYMBOL; @@ -228,10 +231,11 @@ raymarine_read() for (unsigned int rx = 0; rx < 0x3FFF; rx++) { char sect[10]; - char* name; + QString name; snprintf(sect, sizeof(sect), "Rt%d", rx); - if (nullptr == (name = inifile_readstr(fin, sect, "Name"))) { + name = inifile_readstr(fin, sect, "Name"); + if (name.isNull()) { break; } @@ -243,15 +247,15 @@ raymarine_read() char buff[32]; snprintf(buff, sizeof(buff), "Mk%d", wx); - char* str = inifile_readstr(fin, sect, buff); - if ((str == nullptr) || (*str == '\0')) { + QString str = inifile_readstr(fin, sect, buff); + if (str.isEmpty()) { break; } Waypoint* wpt = find_waypt_by_name(str); if (wpt == nullptr) fatal(MYNAME ": No associated waypoint for route point %s (Route %s)!\n", - str, qPrintable(rte->rte_name)); + qPrintable(str), qPrintable(rte->rte_name)); route_add_wpt(rte, new Waypoint(*wpt)); } diff --git a/vecs.cc b/vecs.cc index 4c4a947f5..f7cd6d153 100644 --- a/vecs.cc +++ b/vecs.cc @@ -23,6 +23,7 @@ #include "csv_util.h" #include "gbversion.h" #include "inifile.h" +#include #include #include // qsort @@ -1281,10 +1282,8 @@ find_vec(const char* vecname, const char** opts) if (vec->vec->args) { for (auto ap = vec->vec->args; ap->argstring; ap++) { - const char* opt; - if (res) { - opt = get_option(*opts, ap->argstring); + const char* opt = get_option(*opts, ap->argstring); if (opt) { found = 1; assign_option(svecname, ap, opt); @@ -1292,14 +1291,15 @@ find_vec(const char* vecname, const char** opts) continue; } } - opt = inifile_readstr(global_opts.inifile, vec->name, ap->argstring); - if (opt == nullptr) { - opt = inifile_readstr(global_opts.inifile, "Common format settings", ap->argstring); + QString qopt = inifile_readstr(global_opts.inifile, vec->name, ap->argstring); + if (qopt.isNull()) { + qopt = inifile_readstr(global_opts.inifile, "Common format settings", ap->argstring); } - if (opt == nullptr) { - opt = ap->defaultvalue; + if (qopt.isNull()) { + assign_option(vec->name, ap, ap->defaultvalue); + } else { + assign_option(vec->name, ap, CSTR(qopt)); } - assign_option(vec->name, ap, opt); } } if (opts && opts[0] && !found) { @@ -1338,10 +1338,8 @@ find_vec(const char* vecname, const char** opts) if (vec_list[0].vec->args) { for (auto ap = vec_list[0].vec->args; ap->argstring; ap++) { - const char* opt; - if (res) { - opt = get_option(*opts, ap->argstring); + const char* opt = get_option(*opts, ap->argstring); if (opt) { found = 1; assign_option(svecname, ap, opt); @@ -1349,14 +1347,15 @@ find_vec(const char* vecname, const char** opts) continue; } } - opt = inifile_readstr(global_opts.inifile, svec->name, ap->argstring); - if (opt == nullptr) { - opt = inifile_readstr(global_opts.inifile, "Common format settings", ap->argstring); + QString qopt = inifile_readstr(global_opts.inifile, svec->name, ap->argstring); + if (qopt.isNull()) { + qopt = inifile_readstr(global_opts.inifile, "Common format settings", ap->argstring); } - if (opt == nullptr) { - opt = ap->defaultvalue; + if (qopt.isNull()) { + assign_option(svec->name, ap, ap->defaultvalue); + } else { + assign_option(svec->name, ap, CSTR(qopt)); } - assign_option(svec->name, ap, opt); } } -- 2.30.2